<template>
  <div id="app" ref="appRef">
    <!-- <ScaleBox :width="1920" :height="1080" :isFlat="false"> -->
    <div style="width: 100%; height: 100%" v-if="isShow">
      <router-view />
    </div>
    <!-- </ScaleBox> -->
  </div>
</template>
<script>
import APIS from "@/api/index";

// import drawMixin from '@/utils/drawMixin.js'
import ScaleBox from "vue2-scale-box";
import { yearDate, shangnianyearDate } from "@/utils/common";
export default {
  // mixins: [drawMixin],
  // components: { ScaleBox },
  data() {
    return {
      scaleVal: false,
      isShow: false,
    };
  },
  created() {
    // // 禁止缩放
    // window.addEventListener(
    //   "mousewheel",
    //   function (event) {
    //     if (event.ctrlKey === true || event.metaKey) {
    //       event.preventDefault();
    //     }
    //   },
    //   { passive: false }
    // );
    // //firefox
    // window.addEventListener(
    //   "DOMMouseScroll",
    //   function (event) {
    //     if (event.ctrlKey === true || event.metaKey) {
    //       event.preventDefault();
    //     }
    //   },
    //   { passive: false }
    // );
    // localStorage.removeItem('kspcrightldtqn')
    // localStorage.removeItem('statusarrqn')
    // localStorage.removeItem('statusarr')
    // localStorage.removeItem('kspcrightldt')
    // localStorage.removeItem('kspcbottomtopten')

    this.getislogin();
    this.resizeFun();
    this.getunitListwqx();
    this.getprojectList();
    this.$store.state.scalevalue = (
      (1 / window.devicePixelRatio) * 0.9 +
      0.3
    ).toFixed(2);

    // this.getgetSupplierStateNum();
    // this.getgetSupplierTypeNum();
    // this.gettypeSupplierTOP10();

    // setInterval(() => {
    //   this.getgetSupplierStateNum();
    //   this.getgetSupplierTypeNum();
    //   this.gettypeSupplierTOP10();
    // }, 7200000); //两个小时
  },
  methods: {
    getislogin() {
      APIS.Baseapi.verifyUserLogin()
        .then((res) => {
          this.$store.state.orgType = res.data.orgType - 0;
          this.$store.state.orgCode = res.data.orgCode;
          this.$store.state.orgName = res.data.orgName;
          this.$store.state.userType = res.data.userType;
          this.$store.state.belongUserId = res.data.belongUserId;
          this.$store.state.isLogin = true;
          this.$store.state.menuPermissions = res.data.menuPermissions;
          console.log("1");
          this.getunilistyqx();
          this.isShow = true;
        })
        .catch((err) => {
          this.isShow = true;
          console.log(err);
        });
    },
    getunilistyqx() {
      // unitList
      let arr1 = [{ title: "全部", value: "9", orgcode: "9" }];
      let arr2 = [
        {
          title: "全部",
          orgcode: "999",
          orgname: "全部",
          orgnizationid: "999",
        },
      ];
      APIS.Baseapi.unitList()
        .then((res) => {
          res.data.map((item, index) => {
            if (this.$store.state.orgType == 0) {
              if (
                item.orgname != "浙建集团总承包公司" &&
                item.orgname != "浙建集团工程公司" &&
                item.orgname != "外部客户" &&
                item.orgname != "杭州金顺建设有限公司"
              ) {
                arr1.push({
                  orgcode: item.orgcode,
                  orgname: item.orgname,
                  orgnizationid: item.orgnizationid,
                  title: item.orgname,
                });
                arr2.push({
                  title: item.orgname,
                  orgcode: item.orgcode,
                  orgname: item.orgname,
                  orgnizationid: item.orgnizationid,
                });
              }
            } else {
              arr1.push({
                orgcode: item.orgcode,
                orgname: item.orgname,
                orgnizationid: item.orgnizationid,
                title: item.orgname,
              });
              arr2.push({
                title: item.orgname,
                orgcode: item.orgcode,
                orgname: item.orgname,
                orgnizationid: item.orgnizationid,
              });
            }
          });
          this.$store.state.unitlistarryqx = arr1;
          this.$store.state.unitlistarr = arr2;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getprojectList() {
      let arr1 = [];
      let arr2 = [];
      let arr3 = [];

      APIS.Baseapi.projectList()
        .then((res) => {
          res.data.map((item, index) => {
            arr1.push({
              object: item.object,
              objectid: item.objectid,
              sort: item.sort,
              title: item.objectname,
              sysobject: item.sysobject,
            });
            arr2.push({
              object: item.object,
              objectid: item.objectid,
              sort: item.sort,
              title: item.objectname,
              sysobject: item.sysobject,
            });

            arr3.push({
              object: item.object,
              objectid: item.objectid,
              sort: item.sort,
              title: item.objectname,
              sysobject: item.sysobject,
              active: false,
            });
          });
          this.$store.state.projectlistarr = [
            { title: "全品类", object: "0" },
            ...arr1,
          ];
          this.$store.state.projectlistarr1 = [...arr2];
          this.$store.state.homepageprojectlistarr = [
            { title: "全部", object: "11", active: true },
            ...arr3,
          ];
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getunitListwqx() {
      let arr1 = [{ title: "全部", value: "9", orgcode: "9" }];
      APIS.Baseapi.dictionariesorg()
        .then((res) => {
          res.data.map((item, index) => {
            if (this.$store.state.orgType == 0) {
              if (
                item.orgname != "浙建集团总承包公司" &&
                item.orgname != "浙建集团工程公司" &&
                item.orgname != "外部客户" &&
                item.orgname != "杭州金顺建设有限公司"
              ) {
                arr1.push({
                  orgcode: item.orgcode,
                  orgname: item.orgname,
                  orgnizationid: item.orgnizationid,
                  title: item.orgname,
                });
              }
            } else {
              arr1.push({
                orgcode: item.orgcode,
                orgname: item.orgname,
                orgnizationid: item.orgnizationid,
                title: item.orgname,
              });
            }
          });
          this.$store.state.unitlistwqxarr = arr1;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    resizeFun() {
      let docEle = document.documentElement,
        resizeEvt =
          "orientationchange" in window ? "orientationchange" : "resize",
        resizeFun = () => {
          let clientWidth = docEle.clientWidth;
          if (!clientWidth) return;
          //1920是作为设计图的基准，按照1920*1080
          docEle.style.fontSize = 20 * (clientWidth / 1920) + "px";
          // 20是换算系数，相当于1rem=20px
        };
      if (!document.addEventListener) return;
      window.addEventListener(resizeEvt, resizeFun, false);
      window.addEventListener("DOMContentLoaded", resizeFun, false);
      resizeFun();
    },
    getgetSupplierStateNum() {
      let statusarr = [];
      APIS.Kspc.getSupplierStateNum({}).then((res) => {
        res.data.map((item) => {
          if (item.applyname.includes("优质")) {
            statusarr.push({
              name: "优质分供商",
              num: item.num,
              sort: item.sort,
            });
          } else if (item.applyname.includes("核心")) {
            statusarr.push({
              name: "核心分供商",
              num: item.num,
              sort: item.sort,
            });
          } else if (item.applyname.includes("黑名单")) {
            statusarr.push({ name: "黑名单", num: item.num, sort: item.sort });
          } else if (item.applyname.includes("黄名单")) {
            statusarr.push({ name: "黄名单", num: item.num, sort: item.sort });
          } else if (item.applyname.includes("一般分供商")) {
            statusarr.push({
              name: "一般分供商",
              num: item.num,
              sort: item.sort,
            });
          }
          //   if (item.applyname.includes("待审")) {
          //     statusarr.push({
          //       name: "待审状态",
          //       num: item.num,
          //       sort: item.sort,
          //     });
          //   } else if (item.applyname.includes("备用")) {
          //     statusarr.push({
          //       name: "备用状态",
          //       num: item.num,
          //       sort: item.sort,
          //     });
          //   } else if (item.applyname.includes("优质")) {
          //     statusarr.push({
          //       name: "优质分供商",
          //       num: item.num,
          //       sort: item.sort,
          //     });
          //   } else if (item.applyname.includes("核心")) {
          //     statusarr.push({
          //       name: "核心分供商",
          //       num: item.num,
          //       sort: item.sort,
          //     });
          //   } else if (item.applyname.includes("非生产经营类")) {
          //     statusarr.push({
          //       name: "非生产经营类",
          //       num: item.num,
          //       sort: item.sort,
          //     });
          //   } else if (item.applyname.includes("黑名单")) {
          //     statusarr.push({ name: "黑名单", num: item.num, sort: item.sort });
          //   } else if (item.applyname.includes("黄名单")) {
          //     statusarr.push({ name: "黄名单", num: item.num, sort: item.sort });
          //   }else if(item.applyname.includes("一般分供商")){
          //     statusarr.push({ name: "一般分供商", num: item.num, sort: item.sort });
          //   }
        });
        statusarr.sort((a, b) => b.sort - a.sort);
        const t2 = new Date().getTime() + 10800000;
        let kspcleftobj = { data: statusarr, temp: t2 };
        localStorage.setItem("statusarr", JSON.stringify(kspcleftobj));
      });
    },
    getgetSupplierTypeNum() {
      let renderarrx = [];
      let values = [];
      APIS.Kspc.getSupplierTypeNum({}).then((res) => {
        res.data.sort((a, b) => b.num - a.num);
        const t = new Date().getTime() + 10800000;
        let kspcrightldtobj = { data: res.data, temp: t };
        localStorage.setItem("kspcrightldt", JSON.stringify(kspcrightldtobj));
        // res.data.map((item) => {
        //   let str = item.categoryname.match(/(\S*)供应商/)[1];
        //   renderarrx.push({ name: str, max: res.data[0].num + 1500 });
        //   values.push(item.num);
        // });
      });
    },
    gettypeSupplierTOP10() {
      APIS.Kspc.typeSupplierTOP10({})
        .then((res) => {
          const t1 = new Date().getTime() + 10800000;
          let kspcbottomtoptenobj = {
            data: res.data,
            temp: t1,
          };
          localStorage.setItem(
            "kspcbottomtopten",
            JSON.stringify(kspcbottomtoptenobj)
          );
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang="scss">
@import url("@/assets/font/font.css");
* {
  margin: 0;
  padding: 0;
  list-style: none;
  text-decoration: none;
}
/* 整个滚动条 */
::-webkit-scrollbar {
  // width: 0.05rem;
  // background-color: white;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: #f5f5f5;
}

#app {
  width: 100%;
  height: 100vh;
  box-sizing: border-box;
  color: #2c3e50;
  font-size: 1rem;
  font-family: JCYT;
}
</style>
